package com.competitions.videoedithelper.controller;


import com.competitions.videoedithelper.entity.ResponseModel;
import com.competitions.videoedithelper.service.impl.VideoInfoServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

/***
 * @author 盛旭雯
 */
@CrossOrigin
@RestController
@RequestMapping(value = "/video")
public class VideoInfoController {
    private VideoInfoServiceImpl videoInfoServiceImpl;

    @Autowired
    public VideoInfoController(VideoInfoServiceImpl videoInfoServiceImpl) {
        this.videoInfoServiceImpl = videoInfoServiceImpl;
    }

    @RequestMapping(value = "/upload",method = RequestMethod.POST)
    @ResponseBody
    public ResponseModel uploadVideo(MultipartFile multipartFile, String cusName, int uploadUserId) {
        return videoInfoServiceImpl.uploadVideo(multipartFile, cusName, uploadUserId);
    }

    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public void extractAudio(HttpServletResponse resp, @RequestParam(value = "user_id")int userId,
                             @RequestParam(value = "pageNum", required = false ,defaultValue = "1") int pageNum,
                             @RequestParam(value = "pageSize", required = false ,defaultValue = "10") int pageSize) {
        videoInfoServiceImpl.selectVideos(resp,userId,pageNum,pageSize);
    }

    @RequestMapping(value = "/videoInfo",method = RequestMethod.GET)
    public ResponseModel selectVideo(@RequestParam("videoId") int videoId) {
        return videoInfoServiceImpl.selectVideo(videoId);
    }

    @RequestMapping(value = "/deleteVideo",method = RequestMethod.GET)
    public ResponseModel deleteVideo(@RequestParam("videoId") int videoId) {
        return videoInfoServiceImpl.deleteVideo(videoId);
    }

    @RequestMapping(value = "/selectHistory",method = RequestMethod.GET)
    public ResponseModel selectHistory(@RequestParam("videoId") int videoId) {
        return videoInfoServiceImpl.selectHistory(videoId);
    }

    @RequestMapping(value = "/selectCreated",method = RequestMethod.GET)
    public ResponseModel selectCreated(@RequestParam("userId") int userId) {
        return videoInfoServiceImpl.selectCreated(userId);
    }

    @RequestMapping(value = "/selectEdited",method = RequestMethod.GET)
    public ResponseModel selectEdited(@RequestParam("userId") int userId) {
        return videoInfoServiceImpl.selectEdited(userId);
    }
}
